﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UnwiseSource.Administration.ToolClasses;
using UnwiseSource.ServiceReference1;

namespace UnwiseSource.Administration
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnEnter_Click(object sender, EventArgs e)
        {
            //TODO: Get uname and pass and ask the service if its correct user
            Users user = new Users();
            user.Username = tb_username.Text;
            user.Password = Hasher.HashUsingSHA1(tb_password.Text);

            string accessKey = Helper.getconfigparam("SECID", "");

            Service1Client client = new Service1Client();
            UserCredibility userCreds = client.LogIn(accessKey, user);
            //userCreds.Username = user.Username;

            if (userCreds.Credible)
            {
                Session["userCreds"] = userCreds;

                Response.Redirect("~/Administration/CoursesTool.aspx");
            }
            else
            {
                Error_msg.InnerText = "Грешно потребителско име или парола!";
            }
        }

    }
}